// 云函数入口文件
const cloud = require('wx-server-sdk')

const order = require('./order_change/index');
const coupon = require('./coupon_change/index')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  // db.collection('tb_log').add({ data: event })
  if (/tb_order/.test(event.source)) {
    order.main(event, context);
  } else if (/tb_coupon/.test(event.source)) {
    coupon.main(event, context);
  }

  return {
    event,
    // openid: wxContext.OPENID,
    // appid: wxContext.APPID,
    // unionid: wxContext.UNIONID,
  }
}